<?php
require_once 'phpmailer/class.phpmailer.php';
/**
 * Created by JetBrains PhpStorm.
 * User: Mauro
 * Date: 23/06/11
 * Time: 10:56
 */

class email extends PHPMailer {
    function __construct( $to , $from = null , $body = '' , $subject = '' , $attachment = null) {
        $this->configSMTP();

        $this->AddAddress($to);
        if(is_null($from))
            $this->SetFrom('mauro@mframework.org','mFramework');
        else
            $this->SetFrom($from['email'],$from['name']);
        $this->MsgHTML($body);
        $this->Subject = $subject;
        if(!is_null($attachment))
            $this->AddAttachment($attachment['path'],$attachment['name']);
    }

    function AddAddress($to) {
        if(is_array($to))
        {
            foreach($to as $name => $email)
            {
                parent::AddAddress($email , $name);
            }
        }
        else
            parent::AddAddress($to);
    }

    private function configSMTP() {

    }

    function Send() {
        if(DEBUG)
        {
            if(!parent::Send())
                echo "Mailer Error: " . $this->ErrorInfo;
            else
                echo "Message sent!";
        }
        else
            parent::Send();
    }
}
?>